<?php
    include_once('../include.php');
//    session_start();
    $username = $_POST['username'];
    $password = md5($_POST['password']);
    $verify = $_POST['verify'];
    $verify1 = $_SESSION['verify'];
    $autoFlag = $_POST['autoFlag'];

    if ($verify1 == $verify) {
        connect();
        $sql = "select * from shop_admin where username = '{$username}' and password = '{$password}'";
        $row = checkAdmin($sql);
        if ($row) {
            //如果选择一周内登录
            if ($autoFlag) {
                setcookie("adminId", $row['id'], time() + 7 * 24 * 3600);
                setcookie("adminName", $row['username'], time() + 7 * 24 * 3600);
            }
            $_SESSION['adminName'] = $row['username'];
            $_SESSION['adminId'] = $row['id'];
//            header(location='index.php');
            alertMese('登录成功！', 'index.php');
        } else {
            alertMese('登录失败，重新剑灵', 'login.php');
        }
    } else {
        alertMese('验证码错误', 'login.php');
    }